// Package ioc
/**
* @Project : geektime-basic-go-study
* @File    : web.go
* @IDE     : GoLand
* @Author  : Tvux
* @Date    : 2024/10/7 22:33
**/

package ioc

import (
	"geektime-basic-go-study/webook/backend/internal/web"
	"geektime-basic-go-study/webook/backend/internal/web/article"
	ijwt "geektime-basic-go-study/webook/backend/internal/web/jwt"
	"geektime-basic-go-study/webook/backend/internal/web/oauth2"
	"github.com/HJH0924/GenericGo/logger"
	"github.com/gin-gonic/gin"
	"github.com/redis/go-redis/v9"
)

// InitWebServer
// 初始化 server 使用中间件，注册路由
func InitWebServer(middlewares []gin.HandlerFunc, userHandler *web.UserHandler, wechatHandler *oauth2.WechatHandler, articleHandler *article.Handler) *gin.Engine {
	server := gin.Default()
	server.Use(middlewares...)
	userHandler.RegisterRoutes(server)
	wechatHandler.RegisterRoutes(server)
	articleHandler.RegisterRoutes(server)
	return server
}

func GetMiddlewares(redisClient redis.Cmdable, ujwtHdl ijwt.UserJWTHandler, zl logger.Logger) []gin.HandlerFunc {
	return []gin.HandlerFunc{
		GetCORSMiddleware(),
		//GetSessionMiddleware(),
		GetRateLimitMiddleware(redisClient, zl),
		GetLoginJWTMiddleware(ujwtHdl, zl),
		GetLoggerMiddleware(zl),
	}
}
